﻿using System;
using System.Collections.Generic;
using System.Text;

using AKMII.DMRA.Common;
using AKMII.DMRA.Business.Rule;
using System.Configuration;

namespace AKMII.DMRA.DataLoader
{
    class Program
    {
        static void Main(string[] args)
        {

            Logger.Info("Data Loader started.");

            try
            {
                SendMail();
                Import();
                //Generate();
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occurs in data loader tool", ex);
            }

            Logger.Info("Data Loader finished.");
        }

        private static void Import()
        {
            if (CurrentPeriod.IsImportPeriod)
            {
                Downloader downloader = new Downloader();
                Decryptor decryptor = new Decryptor();
                Formatter formatter = new Formatter();

                downloader.Process(SystemConfiguration.CommonSetting.FolderForDownload);
                decryptor.Process(SystemConfiguration.CommonSetting.FolderForDownload, 
                    SystemConfiguration.CommonSetting.FolderForDecrypt);
                formatter.Process(SystemConfiguration.CommonSetting.FolderForDecrypt);
            }
        }

        private static void Generate()
        {
            if (CurrentPeriod.IsUploadPeriod)
            {
                Generator generator = new Generator();
                Encryptor encrytor = new Encryptor();
                Uploader uploader = new Uploader();

                generator.Process();
                encrytor.Process();
                uploader.Process();
            }
        }

        private static void SendMail()
        {
            MailSender sender = new MailSender();

            if (CurrentPeriod.IsOrderPeriod)
            {
                sender.Process("MarketDirector");
                sender.Process("Administrator");
            }

            //if (CurrentPeriod.IsSendSummaryMailPeriod)
            //{
            //    sender.Process("Administrator");
            //}

            if (CurrentPeriod.IsSendSummaryReportPeriod)
            {
                sender.Process("Summary");
            }

            if (CurrentPeriod.IsSendWeeklyReminderPeriod)
            {
                sender.Process("Weekly");
            }
        }
    }
}
